// @charset "utf-8";

define(function(require, exports, module) {
	var publicMethod = require('../../public/public'),
		clientApi = require('../../public/clientapi');

	var chartModel = require('../model/chartmodel');
	var zhuChart = require('../chart/zhuChart');
	var StockChart = require('../../public/stockchart');

	var template = {
		historyTpml:'',
		timer:'',
		renderUserMsg: function (txt,flag) {
			var self = this;
			
			var html = self.getUserMsg(txt);

			if(!flag){
				html += self.getWaitMsg();
			}else{
				
				self.historyTpml += html;
				return self.historyTpml;
			}
			
			self.appendContent(html);
		},
		getUserMsg:function(txt){
			var tpml = '<div class="usermsg clearfix">' +
					'<img src="http://i.thsi.cn/images/client/exammarket/ths.jpg" class="photo user-photo">' +
					'<div class="msgtext clearfix">' +
						'<i class="icon user-bubble"></i>' +
						'<p class="chat-text">'+ txt +'</p>' +
					'</div>' +
				'</div>';
			return tpml;	
		},
		renderRootText:function(answer,flag){
			var self = this;
			self.removeWaitMsg(flag);
			var txt = answer['txt'];

			var tpml = this.getBaseTpml();

			for(var j = 0, len2 = txt.length; j < len2; j ++){
				var content = $.parseJSON(txt[j]['content']);
				var item = content['item']; 

				//根据content字段对应数据所含信息不同，目前有“百科结果”和“知识类结果”两种状况
				switch (item['type']){
					case 'baike':
						if(item['title']){
							tpml += '<div class="chat-title">'+item['title']+'</div>';
						}
						tpml +=	item['summ']+'</div></div>';
						break;
					case 'knowledge':
						if(item['group'][0]['title']){
							tpml += '<div class="chat-title">'+item['group'][0]['title']+'</div>';
						}
						if(typeof item['group'][0]['summ'] == 'object' && item['group'][0]['summ']['constructor'] == Object){
							tpml += '</div></div>';	
						}else if(typeof item['group'][0]['summ'] == 'string' && item['group'][0]['summ']['constructor'] == String){
							tpml += item['group'][0]['summ'] + '</div></div>';	
						}
				}
			}
			tpml += '</div>';

			//判断是否是只需要模板不需要插入【场景：取历史记录】
			if(flag){
				self.historyTpml += tpml;
				return self.historyTpml;
			}

			self.appendContent(tpml);
		},
		renderRootKefu:function(answer,flag){
			var self = this;
			self.removeWaitMsg(flag);
			var txt = answer['txt'];
			
			var tpml = this.getBaseTpml();

			for(var j = 0, len2 = txt.length; j < len2; j ++){
				var content = $.parseJSON(txt[j]['content']);
				tpml +=	content['answer']+'</div></div>';

			}
			tpml += '</div>';
			
			//判断是否是只需要模板不需要插入【场景：取历史记录】
			if(flag){
				self.historyTpml += tpml;
				return self.historyTpml;
			}

			self.appendContent(tpml);	
		},
		renderDefaultAnswer:function(txt,flag){
			var self = this;
			self.removeWaitMsg(flag);

			var tpml = this.getBaseTpml();
			txt = txt || '您的反馈内容我们已经收到，工作人员会在第一时间进行处理，谢谢。';
			tpml += txt +'</div></div></div>';
			
			//判断是否是只需要模板不需要插入【场景：取历史记录】
			if(flag === 1){
				self.historyTpml += tpml;
				return self.historyTpml;
			}

			self.appendContent(tpml);
		},
		renderWaitAnswer:function(label,labelText,href,type,time){
			var self = this;
			var tpml = this.getBaseTpml();
			time = 2000 || 0;
			//txt = txt ;
			tpml += '正为你打开'+labelText +'</div></div></div>';
			self.appendContent(tpml);
			var $lastRoot = $('#chatContent').find('.robotmsg:last').find('.chat-text');


			clearTimeout(self.timer);
			
			//清空信息
			self.timer = setTimeout(function(){
				//TODO:客户端跳转
				$lastRoot.html('打开<a class="blue" href="###" data-label="'+label+'"  data-href="'+href+'">'+labelText+'</a>');
				self.getOpenType(href,type);
			},time);
		},
		getOpenType:function(href,type){
			switch(type){
				case 1: //1：表示客户端内部页面切换
					
					clientApi.thsQuote.switchPage(href);
					break;
				case 2: //2：表示打开有边框弹窗
					clientApi.openUrlWeb(href,4);
					break;	
			}
		},
		renderZaopan:function(){ //早盘渲染

		},
		renderLabelScroll:function(flag){
			var self = this;
			
			//得到推荐标签内容
			self.appendContent(self.getLabelContent(flag));

			$('.guide-control').labelScroll();
		},
		renderNewslive:function(result,flag){//渲染要闻直播
			var self = this;
			self.removeWaitMsg(flag);

			//得到新闻
			var tpml = self.getBaseTpml()+'为你找到以下要闻直播。'+'</div></div></div>'+ self.getFocusNews(result);
			
			//得到要闻直播的标签内容	
			tpml += self.getLabelContent(2);
			self.appendContent(tpml);

			//标签初始化
			$('.guide-control').labelScroll();			
		},
		renderSolution:function(result,page,len,txt){ //渲染【盘中解盘】
			var self = this;
			txt = txt || '盘中解盘';
			self.removeWaitMsg();
			var tpml = self.getBaseTpml()+'为你找到以下'+txt+'。'+'</div></div></div>' + self.getVarious(result,page,len);

			//得到要闻直播的标签内容	
			tpml += self.getLabelContent(7);
			self.appendContent(tpml);

			chartModel['solution']['page'] += len;

			//标签初始化
			$('.guide-control').labelScroll();		

		},
		getFocusNews:function(result,len){ //得到新闻信息
			var self = this;
			len = len || result.length;
			var tpml = '<div class="focus-news">';
			for( var i = 0; i < len; i ++){
				tpml += '<a data-label="newslink" data-href="'+result[i]['curl']+'" href="###" class="news-item" >'+
								'<p class="news-title" title="'+result[i]['title']+'"><span class="fr">'+self.getDate(result[i]['pubDate'])+'</span>'+self.getSignal(result[i]['nature'])+'<span class="c-content">'+result[i]['title']+'</span></p>'+
								'<p class="news-con" title="'+result[i]['content']+'">摘要：<span class="topic-zy">'+result[i]['content']+'</span></p>'+
							'</a>';
			}
			tpml += '</div>';
			
			return tpml;
		},
		getDate:function(date){//得到新闻转化后的时间
			var dateArr = date.split(' ');
			var everyDate = dateArr[0].split('/');
			return everyDate[1]+'-'+everyDate[2];
		},
		getDate2:function(time){
			var dateAll = new Date(parseInt(time));
			var month = dateAll.getMonth()+1;
			var date = dateAll.getDate();
			return month+'-'+date;
		},
		getVarious:function(result,page,len){ //得到各路观点的信息，盘中解盘也是这个
			var self = this;
			
			len = page + len;

			var tpml = '<div class="focus-news">';
			for( ; page < len; page ++){
				var time = result[page]['ctime'] || result[page]['rtime'];
				tpml += '<a data-label="newslink" data-href="'+result[page]['url']+'" href="###" class="news-item" >'+
								'<p class="news-title" title="'+result[page]['title']+'"><span class="fr">'+self.getDate2(time)+'</span><span class="c-content">'+result[page]['title']+'</span></p>'+
								'<p class="news-con" title="'+result[page]['content']+'">摘要：<span class="">'+result[page]['content'].substring(2)+'</span></p>'+
							'</a>';
			}
			tpml += '</div>';
			
			return tpml;

		},
		getSignal:function(nature){//得到利好中性，利空信号
			
			switch(nature){
				case 1:
					return '<i class="icon i-bg1">利好</i>';
					break;
				case 2:
					return '<i class="icon i-bg1">利空</i>'
					break;
				default:
					return '';
					break;		
			}
		},
		renderFamouslook:function(news){//渲染名家看盘
			var self = this; 
			self.removeWaitMsg();

			var tpml = self.getBaseTpml()+'为你找到以下名家看盘。'+'</div></div></div>'+'<div class="famous">'+
							'<a data-label="famouspeople" data-href="'+news['url']+'" href="###" class="famous-item clearfix">'+
								'<div class="famous-info">'+
									'<div class="famous-photo">'+
										'<img src="'+news['masterInfo']['logo']+'" alt="">'+
										'<p>'+news['author']+'</p>'+
									'</div>'+
									'<p class="famous-title" title="'+news['title']+'">'+
										news['title']+
									'</p>'+
									'<p class="famous-con" title="'+news['content']+'">'+news['content']+'</p>'+
								'</div>'+
							'</a>'+
						'</div>';
			tpml += self.getLabelContent(3);
			self.appendContent(tpml);

			//名家看盘模型页面page+1,下次就渲染下面一条数据
			chartModel['famousLook']['page'] ++;

			
			//标签初始化
			$('.guide-control').labelScroll();	
		},
		renderVarious:function(result,page,len){//渲染各路观点
			var self = this;
			self.removeWaitMsg();

			var tpml = self.getBaseTpml()+'为你找到以下各路观点。'+'</div></div></div>' + self.getVarious(result,page,len);
			
			//得到要闻直播的标签内容	
			tpml += self.getLabelContent(6);
			self.appendContent(tpml);

			//名家看盘模型页面page+1,下次就渲染下面一条数据
			chartModel['various']['page'] +=len;

			//标签初始化
			$('.guide-control').labelScroll();	

		},
		renderLiveSay:function(result,nextName){ 
			var self = this;
			self.removeWaitMsg();
			var tpml = self.getBaseTpml()+'为你找到以下直播大V。'+'</div></div></div>'+'<div class="focus-news">'+
						'<a data-label="liveCircle" data-href="http://t.10jqka.com.cn/circle/'+result['id']+'/" class="circle circle-coco clearfix ">'+
							'<img src="'+result['img']+'" class="c-photo"/>'+
							'<div class="circle-info">'+
								'<p class="c-title clearfix"><span>'+result['name']+'</span><i class="icon">'+result['brokerName']+'</i></p>'+
								'<p class="c-topic"><i class="icon"></i>'+result['topic']+'</p>'+
								'<div class="c-labels">'+
									self.getMarks(result['marks'],3)+
								'</div>'+
							'</div>'+
						'</a>'+
						'<div class="guide-labels circle-prople">'+
							'<div class="labels-box">'+
								'<ul>'+
									'<li data-label="changelivesay"><a href="###">'+nextName+'</a></li>'+
									'<li data-label="changeotherlive"><a href="###">换一批</a></li>'+
								'</ul>'+
							'</div>'+
						'</div>'+
						'</div>';
			tpml += self.getLabelContent(4);		
			// tpml += self.getBaseTpml()+	
			// 		'<a href="###" data-label="changePeople">换一位</a>'+
			// 		'、<a href="###" data-label="technical">技术面大V</a>'+
			// 		'、<a href="###" data-label="steady">稳健型大V</a>'+
			// 		'、<a href="http://t.10jqka.com.cn/newcircle/" target="_blank" data-label="morefamous">看更多</a>'+
			// 		'、<a href="http://t.10jqka.com.cn/newcircle/?applyView=1" target="_blank" data-label="livesay">创建自己的直播室</a>'+
			// 		'</div></div></div>';			
			self.appendContent(tpml);

			//名家看盘模型页面page+1,下次就渲染下面一条数据
			chartModel['liveSay']['page'] ++;

			//标签初始化
			$('.guide-control').labelScroll();				
		},
		getMarks:function(marks,len){ //得到直播大V的marks
			var tpml = '';

			len = len || marks.length;
			if(len <3){
				len = marks.length;
			}

			for(var i = 0; i < len; i ++ ){
				tpml += '<i>'+marks[i]+'</i>';
			}
			return tpml;
		},
		renderPrediction:function(){
			var self = this;
			self.removeWaitMsg();
			var tpml = self.getBaseTpml()+'大数据挖掘，今天可能涨停的股票哦！</div></div></div>'+
					   self.getLabelContent(5);
			self.appendContent(tpml);

			//标签初始化
			$('.guide-control').labelScroll();					

		},
		renderChatTime:function(){
			var self = this;
			var tpml = '<div class="chat-time">'+
							'<span>'+new Date().toLocaleTimeString()+'</span>'+
						'</div>';
			self.appendContent(tpml);		

		},
		renderRootZhengu:function(answer,flag,qtxt){
			this.removeWaitMsg();
			
			var self = this;

			var idx = answer['idx'];
			var hasChat = 0,   //是否有图表
				chatData = ''; //图表数据

			var code = 0;	

			var tpml = self.getBaseTpml('pd1');
			var i = 0;
			for(var j = 0, len2 = idx.length; j < len2; j ++){
				var type = idx[j]['type'];
				
				if( type == 'txt'){ //文本类型

					var content = $.parseJSON(answer[type][i]['content']);
					i ++;
					switch(content['show_type']){
						case 'global':
							
							$.each(content['data']['global']['subjects'],function(k,v){
								tpml += '<p class="answer-head p-zhengu">'+v['name']+'（'+v['code']+'）'+'</p><div class="answer-main">';
							});
							break;
						case 'textzhengu':
							
							tpml += '<div class="answer-cut"><p></p><span>牛叉诊股</span></div>'+
									'<div class="zgdf-info">'+
										'<p class="sub-title">诊股得分：<b>'+content['data']['_score']+'</b>分</p>'+
										'<div class="zgdf-bar">'+
											'<p class="colorbg"><img src="http://i.thsi.cn/images/client/exammarket/colorbg.jpg" alt=""></p>'+
											'<span class="fl">卖出</span>'+
											'<span class="fr">买入</span>'+
											self.getSuggest(content['data']['_bull'])+
										'</div>'+
										'<table class="advise-box">'+
											'<tbody>'+
												'<tr>'+
													'<td class="advise-type">短期建议：</td>'+
													'<td class="advise-text">'+content['data']['_short']+'</td>'+
												'</tr>'+
												'<tr>'+
													'<td class="advise-type">中期建议：</td>'+
													'<td class="advise-text">'+content['data']['_mid']+'</td>'+
												'</tr>'+
												'<tr>'+
													'<td class="advise-type">长期建议：</td>'+
													'<td class="advise-text">'+content['data']['_long']+'</td>'+
												'</tr>'+
											'</tbody>'+
										'</table>'+
									'</div>';
							break;
						case 'msgmonitor':
							
							if(content['title']){
								tpml += '<div class="tgfx-info">'+
										'<p class="sub-title">'+content['title']+'</p>'+
										'<p class="ans-text">'+self.getZhenGuDescs(content['data']['result']['descs'])+'</p>'+
									'</div>';	
							}else{
								tpml += '<div class="monitor-box">'+self.getZhenGuDescs(content['data']['result']['descs'])+'</div>';
							}
							
							break;
						case 'kchart': //行情图
							code = content['data']['show_info']['code'];
							hasChat = 2;
							if(flag){
								tpml += '<div  id="'+chartModel['chat']['id']+'" class="answer-chart answer-chart-kchart"><a href="###" data-href="'+chartModel['chat']['id']+'" data-label="kchart">点击查看图表</a></div>';
							}else{
								tpml += '<div data-label="kchart" id="'+chartModel['chat']['id']+'" class="answer-chart"></div>';	
							}
							

							// //if(answer['diagram']){ 
							// 	var url = 'http://d.10jqka.com.cn/v2/time/hs_'+code+'/last.js';
							// 	// params = {'t':content['data']['show_info']['code']};
							// 	publicMethod.ajaxJson({
							// 		type: 'GET',
							// 		url: url,
							// 		//data: params,
							// 		callback:function(result){
							// 			//tpml += '<div class="answer-chart-pic"><img src="http://comment.10jqka.com.cn/quotepic/t/'+content['data']['show_info']['code']+'.png" /></div>';
							// 		}
							// 	});
									
							//}
							break;	
						default:
							break;		
					}
				}else if( type == 'diagram'){ //图表类
					if(flag){
						tpml += '<div  id="'+chartModel['chat']['id']+'" class="answer-chart"><a data-label="diagram" data-href="'+chartModel['chat']['id']+'" href="###">点击查看图表</a></div>';	
					}else{
						tpml += '<div data-label="diagram" id="'+chartModel['chat']['id']+'" class="answer-chart"></div>';	
					}
					
					hasChat = 1; 
					chatData = answer['diagram'][0];

				}
				

				
			}
			tpml += '</div></div></div></div>';
			
			//判断是否是只需要模板不需要插入【场景：取历史记录】
			if(flag){
				self.historyTpml += tpml;

				//这个时候要看一下是否有图表，先缓存到chartmodel中
					if(hasChat){
						switch(hasChat){
							case 1:
								//缓存内容content
								chartModel['historyChart']['content'].push(chatData);					
								break;
							case 2:
								//缓存股票代码
								chartModel['historyChart']['content'].push(code);	
								break;	
							default:
								break;
						}
						//将图表id缓存到历史记录中
						chartModel['historyChart']['ids'].push(chartModel['chat']['id']);

						//局部id缓存更新
						chartModel['chat']['id'] ++;
					}

				return self.historyTpml;
			}

			//插入模板
			self.appendContent(tpml);

			//判断是否有图表，并加载【必须要在DOM节点存在后再插入】
			if(hasChat === 1){
				zhuChart.renderChat(chartModel['chat']['id'],chatData);
				chartModel['chat']['id'] ++;
			}else if(hasChat === 2){
				
				new StockChart({
					code: code,
					content: '#'+chartModel['chat']['id']
				});
				chartModel['chat']['id'] ++;
			}

		},
		getZhenGuDescs:function(result){
			var self = this;
			var tpml = '';
			for(var i = 0, len = result.length; i < len; i ++){
				tpml += result[i];
			}
			return tpml;
		},
		renderRootIwencai:function(answer,flag,qtxt){
			var self = this;
			this.removeWaitMsg(flag);
			// var baseTpml = self.getBaseTpml();
			// baseTpml += "您好，正在为您查询，请稍等..."+'</div></div>';
			// $('#chatContent').append(baseTpml);	
			
			var tpml = '';
			// if(flag){
			// 	tpml = self.getWaitMsg();
			// }
			for(var i = 0,len = answer['idx'].length; i < len; i ++ ){
				switch(answer['idx'][i]['type']){
					case 'txt':
						
						break;
					case 'table':
						for(var j = 0, len2 = answer['table'].length; j < len2; j ++){
							var nowTable = answer['table'][j];
							var ths = '',trs = '';

							tpml += '<div class="stocks-table ">'+
										'<div class="table-title">'+
											'<a href="###" title="添加到右侧" class="icon add-to-panel" data-s-title="table" data-cond="'+qtxt+'"></a>'+
											'<a href="###" title="从右侧删除" class="icon del-from-panel hide"></a>'+
											'<span title="'+nowTable['title']+'">'+nowTable['title']+'</span>'+
										'</div>'+
										'<table class="stocks-list">'+
											'<colgroup>';

							for(var x = 0, len3 = nowTable['col']; x < len3; x ++){
								if(x == 0){
									tpml += '<col width="'+17+'%">';	
								}else{
									tpml += '<col width="'+83/3+'%">';	
								}
								// if(len3 <= 4){
								// }else{
								// 	if(x == 0){
								// 		tpml += '<col width="'+15+'%">';	
								// 	}else{
								// 		tpml += '<col width="'+85/3+'%">';	
								// 	}
									
								// }
								
								ths += '<td class="txt-c">'+nowTable['th'][x]['first_th_val']+'</td>';
								if(x === 3){
									break;
								}
							}
							tpml += '</colgroup><thead><tr>' + ths + '</tr></thead><tbody>';

							for(var y = 0, len4 = nowTable['tr'].length; y < len4; y ++){
								
								for(var m = 0,len5 = 4; m < len5; m ++){
									if(m === 0){ //表示是股票代码
										var index = nowTable['tr'][y][m]['val'].indexOf('.');
										var code = nowTable['tr'][y][m]['val'].substring(0,index);
										tpml += '<tr data-code="'+code+'">'+
													'<td class="txt-c">'+code+'</td>';			
									}else if(m === 3){
										var className = parseFloat(nowTable['tr'][y][m]['val']) > 0 ? 'red' : 'green';
											className = parseFloat(nowTable['tr'][y][m]['val']) == 0 ? '' : className;

											className = isNaN(parseFloat(nowTable['tr'][y][m]['val'])) ?'':className;
										
										tpml += '<td class="txt-c '+className+'">'+nowTable['tr'][y][m]['val']+'</td>'
									}else{
										tpml += '<td class="txt-c">'+nowTable['tr'][y][m]['val']+'</td>'
									}
									
								}
								tpml += '</tr>';
								if(y === 3){
									break;
								}
							}
							
							//if(len4 > 4){
								tpml += '<tr><td colspan="4"><a class="blue" data-label="ckmore" data-href="'+answer['outside_url']+'" href="###">筛选结果'+nowTable['total_row']+'只,点击查看更多</a></td></tr>';	
								//tpml += '<p class="stocks-more-btn"><a data-label="ckmore" data-href="'+answer['outside_url']+'" href="###">查看更多</a></p>';	
							//}


							tpml += '</tbody></table></div>';
							

						}
						break;
				}
				
			}

			//判断是否是只需要模板不需要插入【场景：取历史记录】
			if(flag){
				self.historyTpml += tpml;
				return self.historyTpml;
			}

			self.appendContent(tpml);

		},
		renderHistoryChat:function(){
			var self =  this;
			
			self.appendContent(self.historyTpml);

		},
		renderGlobalMarket:function(data,codeName){
			var self = this;
			self.removeWaitMsg();

			var tpml  = self.getBaseTpml()+'为你找到以下全球指数数据。'+'</div></div></div>';
			var tableData = '';
			//先遍历循环出表格内部主体数据
			for(var i = 0,len = data.length; i < len;i ++){
				var zdClassName = parseFloat(data[i]['zd']) > 0 ? 'red' : 'green';
					zdClassName = parseFloat(data[i]['zd']) == 0 ? '' : zdClassName;
					zdClassName = isNaN(parseFloat(data[i]['zd'])) ? '' : zdClassName;

				var zdfClassName = parseFloat(data[i]['zdf']) > 0 ? 'red' : 'green';
					zdfClassName = parseFloat(data[i]['zdf']) == 0 ? '' : zdfClassName;	
					zdfClassName = isNaN(parseFloat(data[i]['zdf'])) ? '' : zdfClassName;

				tableData += '<tr data-code="'+data[i]['code']+'">'+
						    '<td class="txt-c">'+codeName[data[i]['code']]+'</td>'+
							'<td class="txt-c">'+data[i]['newprice']+'</td>'+
							'<td class="txt-c '+zdClassName+'">'+data[i]['zd']+'</td>'+
							'<td class="txt-c '+zdfClassName+'">'+data[i]['zdf']+'</td></tr>';
			}
			tpml +=	'<div class="stocks-table ">'+
										'<div class="table-title">'+
											'<a href="###" title="添加到右侧" class="icon add-to-panel" data-s-title="world"></a>'+
											'<a href="###" title="从右侧删除" class="icon del-from-panel hide"></a>'+
											'<span >全球市场('+len+')</span>'+
										'</div>'+
						 '<table class="stocks-list">'+
								'<colgroup>'+
									'<col width="22%">'+
									'<col width="25%">'+
									'<col width="22%">'+
									'<col width="31%">'+
								'</colgroup>'+
								'<thead>'+
									'<tr>'+
										'<td class="txt-c">市场</td>'+
										'<td class="txt-c">最新价(元)</td>'+
										'<td class="txt-c">涨跌</td>'+
										'<td class="txt-c">最新涨跌幅(%)</td>'+
									'</tr>'+
								'</thead>'+
								'<tbody>'+
									tableData+
								'</tbody>'+
							'</table></div>';
			self.appendContent(tpml);
		},
		getBaseTpml:function(thick){
			thick = thick || '';
			var tpml = '<div class="robotmsg clearfix">'+
							'<img src="http://i.thsi.cn/images/client/exammarket/ths.jpg" class="photo"/>'+
							'<div class="msgtext clearfix">'+
							'<i class="icon robot-bubble"></i><div class="chat-text '+thick+'">';
			return tpml;				
		},
		getWaitMsg:function(){
			var tpml = this.getBaseTpml();
			tpml += '您好，正在为您查询，请稍等...</div></div></div>';
			return tpml;
		},
		removeWaitMsg:function(flag){ //移除等待消息
			if(flag){
				return ;
			}
			$('#chatContent').find('.robotmsg:last').remove();
		},
		kpStatistics:function(result){ //开盘统计
			var self = this;

			for(var i =0 ,len = result.length; i < len; i ++){

				var tpml = self.getBaseTpml();
				tpml += '<p >【'+self.getTip(result['type'])+'】</p>'+
						'<p >两市共有'+result[i]['zdtj']['zt']+'个股票涨停，'+result[i]['zdtj']['yzzt']+'只个股一字板涨停，'+result[i]['zdtj']['dt']+'只个股跌停。表现最佳的板块为：'+self.getStrenthConcept(result[i]['strenth_concept']['best'])+
						'表现最弱的板块为：'+self.getStrenthConcept(result[i]['strenth_concept']['weakest'])+'</p>';
				self.appendContent(tpml);			
			}
			
		},
		getTip:function(){
			var self = this;

		},
		getStrenthConcept:function(plate){ //得到涨跌板块
			var self = this;
			var tpml = '';
			for ( var i = 0,len = plate.length; i < len; i ++ ){

				tpml += plate[i]['concept_id'] + '(' + plate[i]['risefall_percent'] + '%)';

				if(i < len -1 ){
					tpml += '、';
				}

			}
			return tpml;

		},
		appendContent:function(tpml){

			var $chatContent = $('#chatContent');
			$chatContent.append(tpml);
			var $parent = $chatContent.parent();
			var lastMsg = $chatContent.find('.robotmsg:last').outerHeight(true);
			var userMsg = $chatContent.find('.usermsg:last').outerHeight(true);
			var scrollTop = $parent[0].scrollHeight - lastMsg  - userMsg -50;
			
			$parent.scrollTop(scrollTop);

		},
		getSuggest:function(bull){
			switch(bull){
				case 1:
					return '<b class="icon zgdf-grade zgdf-grade1">卖出</b>';
				case 2:
					return '<b class="icon zgdf-grade zgdf-grade2">减持</b>';
				case 3:
					return '<b class="icon zgdf-grade zgdf-grade3">中性</b>';
				case 4:
					return '<b class="icon zgdf-grade zgdf-grade4">增持</b>';
				case 5:
					return '<b class="icon zgdf-grade zgdf-grade5">买入</b>';		
				default:
					return '';
			
			}
		},
		getLabelContent:function(flag){ //得到标签轮播里面的内容
			var tpml = '<div class="guide-labels guide-control">'+
							'<a href="###" class="icon label-next-btn hide"></a>'+
							'<a href="###" class="icon label-prev-btn hide"></a>'+
							'<div class="labels-box">'+
						'<ul>';
			switch(flag){
				case 0:  //盘中直播
					tpml += '<li data-label="movements" data-href="10337"><a href="###">dde资金动向</a></li>'+
							'<li data-label="shbo" data-href="639"><a href="###">主力大单</a></li>'+
							'<li data-label="comprehensive" data-href="1246"><a href="###">综合报价</a></li>'+
							'<li data-label="tenplate" data-href="###"><a href="###">资金流入前十板块</a></li>'+
							'<li data-label="fundflow" data-href="9166"><a href="###">资金流向</a></li>'+
							'<li data-label="shortterm" data-href="10733"><a href="###">短线狙击</a></li>'+
							'<li data-label="platemain" data-href="4361"><a href="###">板块主力增仓</a></li>'+
							'<li data-label="platefundflow" data-href="9484"><a href="###">板块资金流向</a></li>'+
							'<li data-label="platerotation" data-href="10724"><a href="###">板块轮动</a></li>';
					break;
				case 1: //早盘
					tpml += '<li data-label="newslive" data-href="###"><a href="###">要闻直播</a></li>'+
							'<li data-label="famouslook" data-href="###"><a href="###">名家看盘</a></li>'+
							'<li data-label="zaopanread" data-href="###"><a href="###">早盘必读</a></li>'+
							'<li  data-label="prediction" data-href="###"><a href="###">涨停预测</a></li>'+
							'<li  data-label="globalmarket" data-href="###"><a href="###">全球市场</a></li>'+
							'<li  data-label="various" data-href="###"><a href="###">各路观点</a></li>'+
							'<li  data-label="solution" data-href="###"><a href="###">盘中解盘</a></li>'+
							'<li  data-label="calendar" data-href="http://stock.10jqka.com.cn/fincalendar.shtml"><a href="###">投资日历</a></li>'+
							'<li data-label="change" data-href="###"><a href="###">换一换</a></li>';
					break;
				case 2:  //要闻直播的标签轮动
					tpml += '<li data-label="newslive" data-href="###"><a href="###">换一批</a></li>'+
							'<li data-label="zklhxw" data-href="###"><a href="###">只看利好新闻</a></li>'+
							'<li data-label="kklkxw" data-href="###"><a href="###">看看利空新闻</a></li>'+
							'<li data-label="ckmore" data-href="http://news.10jqka.com.cn/realtimenews.html"><a href="###">查看更多</a></li>';
					break;	
				case 3: //名家看盘的标签轮动
					tpml += '<li data-label="famouslook" data-href="###"><a href="###">换一位</a></li>'+
							'<li data-label="morefamous" data-href="http://master.10jqka.com.cn/mjdpcl_list/"><a href="###">查看更多名家观点</a></li>'+
							'<li data-label="livesay" data-href="###"><a href="###">看看直播间的大V正在说什么</a></li>';
					break;	
				case 4: 
					tpml += '<li data-label="changeotherlive" data-href="###"><a href="###">换一位</a></li>'+
							'<li data-label="technical" data-href="###"><a href="###">技术面大V</a></li>'+
							'<li data-label="steady" data-href="###"><a href="###">稳健型大V</a></li>'+
							'<li data-label="morefamous" data-href="http://t.10jqka.com.cn/newcircle/"><a href="###">看更多</a></li>'+
							'<li data-label="createlive" data-href="http://t.10jqka.com.cn/newcircle/?applyView=1"><a href="###">创建自己的直播室</a></li>';
					break;	
				case 5:
					tpml += '<li data-label="successwenju" data-href="http://www.iwencai.com/regression/result-normal?qs=backtest_menu2"><a href="###">回测问句成功率</a></li>'+
							'<li data-label="dynamicplate" data-href="###"><a href="###">设为动态板块</a></li>'+
							'<li data-label="amountmuch" data-href="###"><a href="###">量太多,继续筛选</a></li>'+
							'<li data-label="addfree" data-href="###"><a href="###">加为自选股</a></li>';
					break;
				case 6:  //各路观点
					tpml += '<li data-label="various" data-href="###"><a href="###">换一批</a></li>'+
							'<li data-label="zklhxw" data-href="###"><a href="###">只看利好新闻</a></li>'+
							'<li data-label="kklkxw" data-href="###"><a href="###">看看利空新闻</a></li>'+
							'<li data-label="ckmore" data-href="http://stock.10jqka.com.cn/hsdp_list/"><a href="###">查看更多</a></li>';
					break;	
				case 7: //盘中解盘
					tpml += '<li data-label="kkgzjp" data-href="###"><a href="###">看看更早的解盘</a></li>'+
							'<li data-label="jskp" data-href="###"><a href="###">技术看盘</a></li>'+
							'<li data-label="gsqx" data-href="###"><a href="###">股市气象</a></li>'+
							'<li data-label="jpmore" data-href="http://yuanchuang.10jqka.com.cn/djpingpan_list/"><a href="###">查看更多</a></li>';
					break;
				case 8: //收盘后引导文字
					tpml += '<li data-label="mrfp" data-href="http://stock.10jqka.com.cn/fupan/"><a href="###">每日复盘</a></li>'+
							'<li data-label="famouslook" data-href="###"><a href="###">名家看盘</a></li>'+
							'<li data-label="jrrd" data-href="5751"><a href="###">今日热点</a></li>'+
							'<li data-label="various" data-href="###"><a href="###">各路观点</a></li>'+
							'<li data-label="solution" data-href="###"><a href="###">盘中解盘</a></li>';
					break;
				case 9:
					tpml += '<li data-label="cjzx" data-href="http://stock.10jqka.com.cn/fupan/"><a href="###">财经资讯</a></li>'+
							'<li data-label="sjzx" data-href="###"><a href="###">数据中心</a></li>'+
							'<li data-label="wcxg" data-href="5751"><a href="###">问财选股</a></li>';
					break;

			}
			
			tpml += '</ul></div></div>';

			return tpml;
		}
	};

	module.exports = template;
});